package com.elitel.common.elasticSearch;

import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;

public class ESClientPoolFactory implements PooledObjectFactory<ESClient> {
    private String address ;
    private Integer port ;
    private String clustername ;

    public ESClientPoolFactory(String address,int port,String clustername ){
        this.address = address;
        this.port = port;
        this.clustername = clustername;
    }

    public PooledObject<ESClient> makeObject() {
        return new DefaultPooledObject<ESClient>(new ESClient(address, port, clustername));
    }

    public void destroyObject(PooledObject<ESClient> pooledObject) {
        ESClient esClient = pooledObject.getObject();
        esClient.closeClient();
    }

    public boolean validateObject(PooledObject<ESClient> arg0) {
        return true;
    }

    public void activateObject(PooledObject<ESClient> arg0) {
    }

    public void passivateObject(PooledObject<ESClient> arg0) {
    }
}
